package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    /**
     * 用户新增地址
     * @param addressBook
     */
    void insert(AddressBook addressBook);

    /**
     * 用户修改地址
     * @param addressBook
     */
    void update(AddressBook addressBook);

    /**
     * 用户删除地址
     * @param id
     */
    @Delete("delete from address_book where id=#{id}")
    void delete(Long id);

    /**
     * 列出用户地址
     * @param addressBook
     * @return
     */
    List<AddressBook> list(AddressBook addressBook);

    /**
     * 清空用户的默认地址
     * @param userId
     */
    @Update("update address_book set is_default=0 where user_id=#{userId} and is_default=1")
    void clearDefault(Long userId);

    /**
     * 根据id获取地址
     * @param id
     * @return
     */
    @Select("select * from address_book where id=#{id}")
    AddressBook getAddressBookById(Long id);
}
